home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / load < prev    next >
Text File  |  2006-10-19  |  5KB  |  216 lines

  1. * I/O op code 5 - LOAD
  2. *
  3. * This routine loads a program file into the users buffer
  4. *
  5.  
  6. LOAD0  ANDI R12,>FF00
  7.        AI   R12,24
  8.        BL   @GETFDR
  9.        CI   R5,0         See if the file exists
  10.        JNE  LOAD1
  11.  
  12. * If we were doing DSK emulation, go on to the next device
  13. *
  14.  
  15.        ANDI R6,>00FF
  16.        JEQ  LOAD0A
  17.        LDCR @ZERO,4
  18.        DECT @SAVR11
  19.        B    @DSRRT
  20.  
  21. LOAD0A BL   @DSRERR
  22.        DATA >0700        File Error
  23.  
  24. * Check the file header to make sure it has the characters
  25. * 'FI' in bytes 28 and 29
  26. *
  27. * We no longer check for 'FI' because the Myarc does not
  28. * always put it in there.
  29.  
  30. LOAD1
  31.        LDCR @ZERO,4
  32.  
  33. *      MOV  @28(R5),R1
  34. *      CI   R1,'FI'
  35. *      JEQ  LOAD2
  36. *      BL   @DSRERR
  37. *      DATA >0700        File Error
  38.  
  39. * Make sure it is a program file
  40. *
  41. LOAD2
  42.        MOVB @12(R5),R1
  43.        ANDI R1,>0100
  44.        JNE  LOAD3
  45.        BL   @DSRERR
  46.        DATA >0200        Bad Open Attribute
  47.  
  48. * Copy the FDR from the SCSI buffer to DFDR
  49.  
  50. LOAD3  LI   R2,DFDR
  51.        LI   R3,32
  52. LOAD4  MOV  *R5+,R4
  53.        MOV  *R5+,R7
  54.        MOV  *R5+,R8
  55.        MOV  *R5+,R9
  56.        LDCR @B02,4       Select RAM bank 2
  57.        MOV  R4,*R2+
  58.        MOV  R7,*R2+
  59.        MOV  R8,*R2+
  60.        MOV  R9,*R2+
  61.        LDCR @ZERO,4      Select RAM bank 0
  62.        DEC  R3
  63.        JNE  LOAD4
  64.  
  65.        MOV  @PABBUF+2,R10    Get VDP buffer address
  66.  
  67. * Compute the number of bytes in the file
  68. *
  69.        LDCR @B02,4       Select RAM bank 2
  70.        MOV  @DFDR+14,R5  Get number of sectors used by the file
  71.        JEQ  LOAD99       Exit if it is an empty file
  72.        DEC  R5
  73.        MOVB @DFDR+16,R5      Get End of File offset
  74.        JNE  LOAD5
  75.        INC  R5
  76. LOAD5  SWPB R5
  77.  
  78. * See if the user's buffer is big enough to store the entire
  79. * file.  If it isn't, we will decrease the number of bytes
  80. * we read accordingly.
  81. *
  82.        LDCR @ZERO,4
  83.        C    R5,@PABBUF+6
  84.        JL   LOAD6
  85.        MOV  @PABBUF+6,R5
  86.        JEQ  LOAD99       Exit if buffer is zero bytes long
  87. LOAD6
  88.  
  89. * Set up the rest of the registers.  They are used as follows:
  90. *
  91. * R1 - Points to data chain in the FDR
  92. * R2 - Current AU that we're reading
  93. * R3 - Current sector within the AU
  94. * R5 - Number of bytes remaining to be read
  95. * R10 - Buffer address in VDP or CPU memory
  96. * R11 - # of sectors per AU on this disk
  97. *
  98.  
  99.        LDCR @B04,4       Select RAM bank 4
  100.        MOV  R6,R4        Get drive #
  101.        SRL  R4,8
  102.        SLA  R4,1
  103.        MOV  @SAUTBL(R4),R11
  104.  
  105.        LDCR @B02,4       Select RAM bank 2
  106.        LI   R1,DFDR+40   Point to data chain
  107. LOAD8  MOV  *R1+,R2      Get 1st AU of the file
  108. LOAD9  CLR  R3
  109.  
  110. * Now begin reading sectors from the file until we have
  111. * read all the bytes in the file!
  112. *
  113.  
  114. LOAD10 MOV  R2,R7        Get AU we need to read
  115.        MPY  R11,R7           Convert AU to sector
  116.        A    R3,R8            Add in sector within AU
  117.        JNC  LOAD11
  118.        INC  R7
  119. LOAD11 LI   R4,SECBUF
  120.        SRL  R8,1         Convert sector to block #
  121.        JNC  LOAD12
  122.        AI   R4,>100
  123. LOAD12 SRL  R7,1
  124.        JNC  LOAD13
  125.        AI   R8,>8000
  126.  
  127. * Now check to see if we can read the read a 512 byte block
  128. * directly into VDP RAM.  If so, we will use sector I/O
  129. * routines to read the data.  Otherwise, we use BANKIT to
  130. * store the data in SECBUF first.
  131. *
  132. * We can do 512 bytes if -
  133. *  a) There are at least 512 bytes left to read in the file
  134. *  b) We start reading in the 1st half of SECBUF
  135. *  c) The 2nd half of SECBUF contains nect 256 bytes of file
  136. *
  137. LOAD13
  138.        LDCR @ZERO,4
  139.  
  140.        CI   R5,512           See how much is left to read
  141.        JL   LOAD14
  142.  
  143.        CI   R4,SECBUF
  144.        JNE  LOAD14
  145.  
  146.        MOV  R11,R9
  147.        S    R3,R9
  148.        CI   R9,1
  149.        JNE  LOAD20
  150.  
  151. * Well, it didn't work out.  We have to read the 512 byte
  152. * block into SECBUF and copy it to VDP memory from there.
  153. *
  154. LOAD14 BLWP @BANKIT      Read the block from the disk
  155.        DATA SCSIRD
  156.        JEQ  LOAD15
  157.        BL   @DSRERR
  158.        DATA >0600        Device error
  159. LOAD15 MOV  R10,R0       Set VDP write address
  160.        ORI  R0,>4000
  161.        SWPB R0
  162.        MOVB R0,@VDPWA        Maybe MOVB R0,*R15?
  163.        SWPB R0
  164.        MOVB R0,@VDPWA
  165.  
  166.        LI   R0,256
  167.        A    R0,R10       Adjust buffer pointer
  168. LOAD16 MOVB *R4+,@VDPWD  Copy the sector to the user's buffer
  169.        DEC  R5
  170.        JEQ  LOAD99       See if we're done
  171.        DEC  R0
  172.        JNE  LOAD16
  173.        INC  R3
  174. LOAD17
  175.        C    R3,R11            See if we've read all the sectors in this AU
  176.        JL   LOAD10            If not, go back and keep reading
  177.  
  178.        LDCR @B02,4       Select RAM bank 2
  179.        C    R2,*R1       See if we're at the last AU in this cluster
  180.        JEQ  LOAD18       If so, go to next cluster
  181.        INC  R2           Otherwise, go to next AU
  182.        JMP  LOAD9
  183. LOAD18 INCT R1           Go to next cluster
  184.        JMP  LOAD8
  185.  
  186.  
  187. LOAD99 BL   @DSRERR
  188.        DATA 0            No error
  189.  
  190. **
  191. *
  192. * LOAD20
  193. *
  194. *  This is where we use sector I/O to read 512 bytes
  195. *  directly from the SCSI drive to VDP memory.
  196. *
  197. **
  198.  
  199. LOAD20
  200.        MOV  R6,R0            Get SCSI ID
  201.        ORI  R0,>4000         Set sector size and VDP memory
  202. *      AI   R0,>100
  203.        MOVB R0,@>834C
  204.        MOVB @B01,@>834D      Read
  205.        MOV  R10,@>834E       Buffer address
  206.        MOV  R8,@>8350        Sector to read
  207.        MOV  R7,@>8352           "       "
  208.  
  209.        BLWP @BANKIT
  210.        DATA SCSI20
  211.        AI   R5,-512          Adjust # of bytes left to read
  212.        JEQ  LOAD99
  213.        AI   R10,512          Adjust buffer pointer
  214.        INCT R3
  215.        JMP  LOAD17
  216.